import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Router } from '@angular/router';
import { ConfigService } from '../../../core/common/config.service';
import { TranslateService } from '@ngx-translate/core';
@Component({
      selector: 'app-settlemanage',
      templateUrl: './settlemanage.component.html',
      styleUrls: ['./settlemanage.component.scss']
})
export class SettleManageComponent implements OnInit {
      public settlemanage: any;
      constructor(public configService: ConfigService, public http: Http, public router: Router , private translate: TranslateService) {

      }
      ngOnInit() {
            this.initTableData();
      }
      public initTableData(): void {
            const url = this.configService.get('url') + '?service=ChnlBillService&method=getChnlBillInfo';
            this.http.post(url, { 'start_date': '2017-05-01', 'end_date': '2050-05-31' }).toPromise().then(data => {
                  // console.log(data);
                  if (data.json().code === '0000') {
                        this.settlemanage = data.json().info;
                        // console.log(this.settlemanage);
                        this.translate.get('account.settlemanage.settleAccounts').subscribe((res: any) => {
                              this.settlemanage.forEach((item) => {
                                    switch (item.bill_tag) {
                                          case '1': item.bill_tag = res.uncleared;
                                                break;
                                          case '2': item.bill_tag = res.closedAccount;
                                                break;
                                          case '3': item.bill_tag = res.partialSettlement;
                                                break;
                                    }
                              });
                        });
                  }else {
                        console.log(data.json().message);
                  }
            });
      }
      onRowSelect(data): void {
            // console.log(data);
            this.router.navigate(['/account/settledetail', data.data.total_id, data.data.chnl_id], { skipLocationChange: true });
      }
}
